<template>
<uni-shadow-root class="partials-nearShop-nearShop"><import src="../../wxParse/wxParse.wxml"></import>
<import src="simpleNearShop.wxml"></import>  
<import src="near_shop_slide/near_shop_slide.wxml"></import>  
<import src="gongyi_near_shop/index.wxml"></import>  
<import src="gongyi_near_shop_two/index.wxml"></import>  
<block v-if="data.androidTemplate == """>
    <template is="simpleNearShop" :data="...data,shops,defaultColor"></template> 
</block>
<block v-if="data.androidTemplate == "near_shop_slide"">
    <template is="near_shop_slide" :data="...data,shops,journey,defaultColor"></template> 
</block>
<block v-if="data.androidTemplate == "gongyi_shop_list"">
    <template is="gongyi_shop_list" :data="...data,shops,journey,defaultColor"></template> 
</block>
<block v-if="data.androidTemplate == "gongyi_shop_two_list"">
    <template is="gongyi_shop_two_list" :data="...data,shops,journey,defaultColor"></template> 
</block></uni-shadow-root>
</template>

<script>

global['__wxRoute'] = 'partials/nearShop/nearShop'
const app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Component({
  properties: {
    data: {
      type: JSON,
      value: 'default value',
    }
  },
  data: {
    someData: {},
    page:"1",
    shops:[],
    journey:[],//公里数
  },
  ready:function(){
    this.getData();
    if (app.globalData.setting.platformSetting.defaultColor && app.globalData.setting.platformSetting.defaultColor !=""){
      app.globalData.consoleFun("=====nearShop组件-defaultColor=====",[this.data.data,app.globalData.setting.platformSetting.defaultColor])
      // 有默认色
      this.setData({
        defaultColor: app.globalData.setting.platformSetting.defaultColor
      })
    }
    else{
      // 没有默认色
      this.setData({
        defaultColor: app.globalData.setting.platformSetting.defaultColor
      })
    }
  },
  methods: {
      toProlinkUrl: function (e) {
        app.globalData.consoleFun("=====productList组件-tolinkUrl=====",[e.currentTarget.dataset.info])
        let productData = e.currentTarget.dataset.info
        let link="";
        if (productData.productType==6){
          link = "ticket_detail.html?productId=" + productData.id; 
        }else{
          link = "product_detail.html?productId=" + productData.id; 
        }
        app.globalData.linkEvent(link);
      },
      // 定位
      clickCatch: function (e) {
        console.log("===clickCatch===",e);
        let itemData=e.currentTarget.dataset.item
        let latitude = itemData.latitude;
        let longitude = itemData.longitude;
        let name = itemData.shopName;
        let address = itemData.shopLocation;
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          scale: 12,
          name: name,
          address: address
        });
      },
    tolinkUrl: function (e) {
      app.globalData.consoleFun("=====nearShop组件-link=====",[e.currentTarget.dataset.link])
      let linkUrl = e.currentTarget.dataset.link
      app.globalData.linkEvent(linkUrl)
    },
    getData:function(){
      let that = this;
      let shopName = app.globalData.setting.platformSetting.defaultShopBean.account.shopName
      wx.getLocation({
        type: 'gcj02',
        success: function (res) {
          let latitude = res.latitude
          let longitude = res.longitude
          app.globalData.consoleFun("=====nearShop组件-getLocation=====",[longitude,latitude,that.data.page])
          let pageParam = { 
            "longitude": longitude,
            "latitude": latitude,
            "page": that.data.page,
            "pageObjectType":that.data.data.pageObjectType||0,
            "pageObjectId":that.data.data.pageObjectId||0
          }
          if(that.data.data.jsonData.shopTypeId){
              pageParam=Object.assign({},pageParam,{ "shopTypeId":that.data.data.jsonData.shopTypeId})
          }
          app.globalData.consoleFun("=====nearShop组件-pageParam=====",[pageParam])
          let customIndex = app.globalData.AddClientUrl("/more_near_shops.html", pageParam, 'get', 1)
          app.globalData.showToastLoading('loading', true)
          wx.request({
            url: customIndex.url,
            header: app.globalData.header,
            method: 'GET',
            success: function (res) {
              that.setData({
                shops: res.data.relateObj.result
              })
              app.globalData.consoleFun("=====nearShop组件-success=====",[res,res.data.relateObj.result])
              // 店铺标签是带【】的字符串需要改
              let shops = res.data.relateObj.result;
              let tagArray=[];
              for (let j = 0; j < shops.length; j++) {
                // 获取公里数
                shops[j].distance = app.globalData.getDistance(latitude, longitude, shops[j].latitude, shops[j].longitude)
                if (shops[j].shopTag) {
                  tagArray = shops[j].shopTag.slice(1, -1).split("][")
                  shops[j].tagArray = tagArray;
                }
              }
              that.setData({shops: shops})
              if (res.data.errcode < 0) {
                app.globalData.consoleFun("=====nearShop组件-fail=====",[res.data.errMsg])
              }
              else {
                wx.hideLoading()
              }
            },
            fail: function (res) {
              wx.hideLoading()
              app.globalData.loadFail()
            }
          })
        }
      })
    },
  },
})
export default global['__wxComponents']['partials/nearShop/nearShop']
</script>
<style platform="mp-weixin">
@import 'near_shop_slide/near_shop_slide.css';/* 引入滑动的附近店铺列表 */
@import 'gongyi_near_shop/index.css';/* 引入滑动的附近店铺列表 */
@import 'gongyi_near_shop_two/index.css';/* 引入滑动的附近店铺列表 */
.tags_content::-webkit-scrollbar{
    width: 0;
    height: 0;
    color: transparent;
    display:none ;
}
/*没有相关商品  */
.noproduct{
  width: 100%;
  height: 200rpx;
  text-align: center;
  display: flex;
  flex-direction: column;
}
.noproduct image{
  width: 150rpx;
  height: 150rpx;
  margin: 0 auto;
}
.noproduct text{
  font-size: 30rpx;
}
.store_list{
  display: flex;
  flex-direction: column;
  overflow: hidden
}
.store_item{
  display: flex;
  flex-direction: row;
  padding: 20rpx;
}
.store_item_left{
  margin-right: 20rpx;
}
.store_item_logo{
  width:150rpx;
  height: 150rpx; 
  border-radius:10rpx;
}
.store_item_right{
  display: flex;
  flex-direction: column;
  width: 75%;
}
.store_item_name{
  font-size: 30rpx;
  color: #333;
  margin-bottom: 20rpx;
}
.store_item_service{
  font-size: 22rpx;
  color: #999;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.tags_content{
  display: flex;
  flex-direction: row;
  align-items: center;
  overflow-x:hidden;
  width:100%;
  height:50rpx;
  white-space: nowrap;
}
.tags_item{
  border: 2rpx solid #eee;
  padding: 2rpx 12rpx;
  font-size: 22rpx;
  color: #888;
  margin-right: 10rpx;
  border-radius: 4rpx;
  white-space:nowrap;
  box-sizing: content-box;
  display:inline-block;
}
</style>